#include <iostream>

using namespace std;
using ll=long long;
const ll MOD=200907;

ll qmi(ll a,ll b)
{
	ll ret=1;
	while(b)
	{
		if(b&1)
		{
			ret=ret*a%MOD;
		}
		a=a*a%MOD;
		b>>=1;
	}
	return ret;
}
int main()
{
	int t;
	cin>>t;
	while(t--){
		ll a,b,c,k;
		cin>>a>>b>>c>>k;
		if(a+c==2*b)
			cout<<(a+(k-1)*(b-a)%MOD)%MOD<<endl;
		else
			cout<<a*qmi(b/a,k-1)%MOD<<endl;
	}
	
	return 0;
}
